package com.sz.service;

import com.sz.dao.IUserDao;
import com.sz.pojo.User;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class UserSVImpl implements IUserSV{
    @Resource
    private IUserDao userDao;

    @Override
    public User getUserByUsername(String username) {
        return userDao.getUserByUsername(username);
    }

    @Override
    public int updateName(String username, String name) {
        int i = userDao.updateName(username, name);
        if(i>0) System.out.println("成功修改了"+i+"条记录");
        else System.out.println("无修改");
        return i;
    }

    @Override
    public int updatePassword(String username, String password) {
        int i = userDao.updatePassword(username, password);
        if(i>0) System.out.println("成功修改了"+i+"条记录");
        else System.out.println("无修改");
        return i;
    }

    @Override
    public int updateRemarks(String username, String remarks) {
        int i = userDao.updateRemarks(username, remarks);
        if(i>0) System.out.println("成功修改了"+i+"条记录");
        else System.out.println("无修改");
        return i;
    }

    @Override
    public int addUser(User user) {
        return userDao.addUser(user);
    }

    @Override
    public boolean isHaveUsername(String username) {
        int id=0;
        id = userDao.getIdByUsername(username);
        if (id>0) return true;
        else return false;
    }

    @Override
    public List<User> getAllByAuth(int auth) {
        return userDao.getAllByAuth(auth);
    }

    @Override
    public int updateOneById(User user) {
        return userDao.updateOneById(user);
    }

    @Override
    public int deleteOneById(User user) {
        return userDao.deleteOneById(user);
    }
}
